/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: UnitModel.java 579 2010-07-26 12:23:07Z YongPeng $
 *   $LastChangedDate: 2010-07-26 12:23:07 +0000 (Mon, 26 Jul 2010) $
 *   $LastChangedBy: YongPeng $
 *--------------------------------------------------------------------------
 */
package battlefield.entity;

import battlefield.state.UnitType;
import java.io.Serializable;

/**
 *
 * @author Harry Nguyen
 */
public class UnitModel implements Serializable {

    private int id;
    private String name;
    private int rows;
    private int columns;
    private int price;
    private String unitImage;
    private String destroyedImage;
    private boolean[][] transparency;
    private UnitType type;

    /**
     * Constructs a UnitModel object with the following parameters
     * @param id unique id to identify the object
     * @param name name of the model
     * @param rows which row the unit is on
     * @param columns which column the unit is on
     * @param price the price of the unit
     * @param unitImage the path to the source of the unit image
     * @param destroyedImage the path to the source of the destroyed image
     * @param type the type of unit
     */
    public UnitModel(int id, String name, int rows, int columns, int price, String unitImage, String destroyedImage, UnitType type) {
        this.id = id;
        this.name = name;
        this.rows = rows;
        this.columns = columns;
        this.price = price;
        this.unitImage = unitImage;
        this.destroyedImage = destroyedImage;
        this.transparency = new boolean[rows][columns];
        this.type = type;
    }

    /**
     * Returns the id of the UnitModel
     * @return int of the id
     */
    public int getId() {
        return id;
    }

    /**
     * Sets the id of the unit model
     * @param id
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Returns the name of the unit
     * @return String name of the unit
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of the Unit
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the row the unit is on
     * @return int
     */
    public int getRows() {
        return rows;
    }

    /**
     * Set the number of rows the unit occupy
     * @param rows the unit occupy
     */
    public void setRows(int rows) {
        this.rows = rows;
    }

    /**
     * Return the number of columns the unit occupy
     * @return int of the number of columns the unit occupy
     */
    public int getColumns() {
        return columns;
    }

    /**
     * Sets the number of columns the unit occupy
     * @param columns the unit occupy
     */
    public void setColumns(int columns) {
        this.columns = columns;
    }

    /**
     * Returns the price of the unit
     * @return int of the price
     */
    public int getPrice() {
        return price;
    }

    /**
     * Sets the price of the unit
     * @param price amount to set
     */
    public void setPrice(int price) {
        this.price = price;
    }

    /**
     * Returns the source of the image
     * @return string of the image source
     */
    public String getUnitImage() {
        return unitImage;
    }

    /**
     * Sets the string of the unit image
     * @param unitImage path to the source of the unit image
     */
    public void setUnitImage(String unitImage) {
        this.unitImage = unitImage;
    }

    /**
     * Returns the source of the destroyed image
     * @return path to the source of the destroyed image
     */
    public String getDestroyedImage() {
        return destroyedImage;
    }

    /**
     * Sets the source of the destroyed image
     * @param destroyedImage string path to the destroyed image
     */
    public void setDestroyedImage(String destroyedImage) {
        this.destroyedImage = destroyedImage;
    }

    /**
     * Returns the visibility of the unit through the use of a 2d array
     *
     * @return a 2d array of the visibility of the unit
     */
    public boolean[][] getTransparency() {
        return transparency;
    }

    /**
     * Returns if there is a cell at the x and y position
     * 
     * @param x position
     * @param y position
     * @return if there is a cell at x and y position
     */
    public boolean hasCellAt(int x, int y) {
        return !transparency[x][y];
    }

    /**
     * Return UnitType of the unit
     *
     * @return the type of the unit
     */
    public UnitType getType() {
        return type;
    }

    /**
     * Sets the UnitType of Unit
     * 
     * @param type the UnitType of the unit
     * @see UnitType
     */
    public void setType(UnitType type) {
        this.type = type;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }

        if (!(obj instanceof UnitModel)) {
            return false;
        }

        return ((UnitModel) obj).getId() == this.getId();
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.id;
        return hash;
    }
}
